
<template>
    <div class="search-load-comp">
        <!-- <div class="load-cont">
            <div class="img-wrap">
                <el-image class="load-img show-img" :src="loadImg" fit="contain" />
                <el-image class="load-img hover-img" :src="loadhoverImg" fit="contain" />
                <el-image class="load-img active-img" :src="loadactiveImg" fit="contain" />
            </div>

            <div class="img-wrap arrow-box">
               <el-icon class="arrow-img"><CaretBottom /></el-icon>
            </div>

        </div>
    </div> -->
    <el-popover
            placement="bottom-start"
            trigger="hover"
            popper-class="load-drop-box">
            <template #reference>
                <div class="load-cont">
                    <div class="filter-cont">
                        <div class="img-wrap">
                            <el-image class="load-img show-img" :src="loadImg" fit="contain" />
                            <el-image class="load-img hover-img" :src="loadhoverImg" fit="contain" />
                            <el-image class="load-img active-img" :src="loadactiveImg" fit="contain" />
                        </div>

                        <div class="img-wrap arrow-box">
                        <el-icon class="arrow-img"><CaretBottom /></el-icon>
                        </div>
                    </div>
                </div>
            </template>

            <div class="load-cont-box">
                <div class="load-cont-wrap">
                    <div class="load-item" @click.stop="toLoad(1)">CSV</div>
                    <div class="load-item" @click.stop="toLoad(2)">TXT</div>
                </div>
                <!-- <div v-else class="load-cont-wrap">
                    <div class="load-item">暂无接口</div>
                </div> -->
            </div>
        </el-popover>
    </div>
</template>

<script setup>
    import { ref, toRefs, reactive, computed } from 'vue'
    import { controlStore } from '@/stores/control'

    import loadImg from '@/assets/img/load.png'
    import loadhoverImg from '@/assets/img/load-hover.png'
    import loadactiveImg from '@/assets/img/load-active.png'
    import { getPresciptionDownLoad,
        getPresciptionSearchDownLoad,
        downPrescriptionBasic,
        downPrescriptionHerb,
        downHerbSearch,
        downHerb,
        downIngredientSearch,
        downIngredient,
        downDiseaseSearch,
        downDisease,
        downPrescrIngre,
        downPrescrTarget,
        downPrescrExperimet,
        downHerbDetail,
        downHerbIngredient,
        downHerbTarget,
        downHerExperment,
        downHerbPrescription,
        downHerbCombin,
        downHerbDisease,
        downIngredientBasic,
        downIngreComTarget,
        downIngreRelateHerb,
        downIngreRelateIngre,
        downSynerIngre,
        downSynerDisease,
        downExperIngreRecords,
        downDiseaseBasic,
        downDiseaseAssIngre,
        downDiseaseAssHerb,
        dowmDiseaseAssPres,
        downpreNetwork,
        downHerbnetwork,
        downHerbherbNetwork,
        downingreingreNetwork,
        downPreDiseaNetwork,
        downHerbDiseaNetwork,
        downIngreDiseaNetwork,
        downAdmetpage
    } from '@/service/tcm'
    import {createExcel, creatTxt } from '@/utils/util'

    // const emitter = defineEmits(['onChg']);
    const props = defineProps({
        type: {
            type: [Number, String],
            default: -1
        },
        uiCode: {
            type: String,
            default: ''
        },
        para: {
            type: Object,
            default: () => {
                return {}
            }
        }
    });
    const { type, uiCode, para } = toRefs(props);
    const toLoad = (t) => {
        switch (type.value) {
            case 'prescription':
                toGetPresciptionDownLoad(t);
                break;
            case 'prescriptionSearch':
                toGetPresciptionSearchDownLoad(t);
                break;
            case 'prescriptionDetailBasic':
                toDownPrescriptionBasic(t);
                break;
            case 'prescriptionHerb':
                toDownPrescriptionHerb(t);
                break;
            case 'herb':
                toDownHerb(t);
                break;
            case 'herbSearch':
                toDownHerbSearch(t);
                break;
            case 'ingredient':
                toDownIngredient(t);
                break;
            case 'ingredientSearch':
                toDownIngredientSearch(t);
                break;
            case 'disease':
                toDownDisease(t);
                break;
            case 'diseaseSearch':
                toDownDiseaseSearch(t);
                break;
            case 'prescriptionIngredient':
                toDownPrescrIngre(t);
                break;
            case 'prescrTarget':
                toDownPrescrTarget(t);
                break;
            case 'prescrExperment':
                toDownPrescrExperimet(t);
                break;
            case 'herbDetailBasic':
                toDownHerbDetail(t);
                break;
            case 'herbIngredient':
                toDownHerbIngredient(t);
                break;
            case 'herbTarget':
                toDownHerbTarget(t);
                break;
            case 'herbExperiment':
                toDownHerExperment(t);
                break;
            case 'herbPrescription':
                toDownHerbPrescription(t);
                break;
            case 'herbCombinHerb':
                toDownHerbCombin(t);
                break;
            case 'herbDisease':
                toDownHerbDisease(t);
                break;
            case 'ingredientBasic':
                toDownIngredientBasic(t);
                break;
            case 'ingreCompTarget':
                toDownIngreComTarget(t);
                break;
            case 'ingredientRelateHerb':
                toDownIngredientRelateHerb(t);
                break;
            case 'ingrRelateIngre':
                toDownIngreRelateIngre(t);
                break;
            case 'ingreLandAsyerIngre':
                toDownAsyerIngre(t);
                break;
            case 'ingreAsyerDisease':
                toDownAsyerDisease(t)
                break;
            case 'ingredientExperRecods':
                toDownExperIngreRecords(t);
                break;
            case 'diseaseBasic':
                toDownDiseaseBasic(t);
                break;
            case 'diseaseAssIngre':
                toDownDiseaseAssIngre(t);
                break;
            case 'diseaseAssHerb':
                toDiseaseAssHerb(t);
                break;
            case 'diseaseAssPrescription':
                toDowmDiseaseAssPres(t);
                break;
            case 'pre_network':
                toDownpreNetwork(t)
                break;
            case 'herb_network':
                toDownHerbnetwork(t);
                break;
            case 'herb_herb_networtk':
                toDownHerbherbNetwork(t);
                break;
            case 'ingredient_To_Network':
                toDowningreingreNetwork(t);
                break;
            case 'pre_disease_network':
                toDownPreDiseaNetwork(t);
                break;
            case 'herb_disease_network':
                toDownHerbDiseaNetwork(t);
                break;
            case 'herb_disease_network':
                toDownIngreDiseaNetwork(t);
                break;
            case 'admet_herb_down':
                toDownAdmetpage(t);
                break;
        }
    };
//prescription带分析饼图查询结果下载
const toGetPresciptionDownLoad = (t) => {
    getPresciptionDownLoad({...para.value, exportType: t}).then(res => {
        const name = res.headers['content-disposition'] ? res.headers['content-disposition'].split('filename=')[1] : (t == 1 ? 'down.csv' : 'down.txt');
        t == 1 ? createExcel(res.data, name) : creatTxt(res.data, name);
    })
}
//prescription查询结果下载
const toGetPresciptionSearchDownLoad = (t) => {
    getPresciptionSearchDownLoad({...para.value, exportType: t}).then(res => {
        const name = res.headers['content-disposition'] ? res.headers['content-disposition'].split('filename=')[1] : (t == 1 ? 'down.csv' : 'down.txt');
        t == 1 ? createExcel(res.data, name) : creatTxt(res.data, name);
    })
}
//prescription详情base下载
const toDownPrescriptionBasic = (t) => {
    downPrescriptionBasic({...para.value,  exportType: t}).then(res => {
        const name = res.headers['content-disposition'] ? res.headers['content-disposition'].split('filename=')[1] : (t == 1 ? 'down.csv' : 'down.txt');
        t == 1 ? createExcel(res.data, name) : creatTxt(res.data, name);
    })
}

//处方-herb信息下载
const toDownPrescriptionHerb = (t) => {
    downPrescriptionHerb({...para.value,  exportType: t}).then(res => {
        const name = res.headers['content-disposition'] ? res.headers['content-disposition'].split('filename=')[1] : (t == 1 ? 'down.csv' : 'down.txt');
        t == 1 ? createExcel(res.data, name) : creatTxt(res.data, name);
    })
}
//处方-network下载
const toDownpreNetwork = (t) => {
    downpreNetwork({...para.value,  exportType: t}).then(res => {
        const name = res.headers['content-disposition'] ? res.headers['content-disposition'].split('filename=')[1] : (t == 1 ? 'down.csv' : 'down.txt');
        t == 1 ? createExcel(res.data, name) : creatTxt(res.data, name);
    })
}
//her 带统计图的下载
const toDownHerb = (t) => {
    downHerb({...para.value,  exportType: t}).then(res => {
        const name = res.headers['content-disposition'] ? res.headers['content-disposition'].split('filename=')[1] : (t == 1 ? 'down.csv' : 'down.txt');
        t == 1 ? createExcel(res.data, name) : creatTxt(res.data, name);
    })
}
//herb搜索结果页下载
const toDownHerbSearch = (t) => {
    downHerbSearch({...para.value,  exportType: t}).then(res => {
        const name = res.headers['content-disposition'] ? res.headers['content-disposition'].split('filename=')[1] : (t == 1 ? 'down.csv' : 'down.txt');
        t == 1 ? createExcel(res.data, name) : creatTxt(res.data, name);
    })
}

//ingredient首页带统计的下载
const toDownIngredient = (t) => {
    downIngredient({...para.value,  exportType: t}).then(res => {
        const name = res.headers['content-disposition'] ? res.headers['content-disposition'].split('filename=')[1] : (t == 1 ? 'down.csv' : 'down.txt');
        t == 1 ? createExcel(res.data, name) : creatTxt(res.data, name);
    })
}
//ingredient-search下载
const toDownIngredientSearch = (t) => {
    downIngredientSearch({...para.value,  exportType: t}).then(res => {
        const name = res.headers['content-disposition'] ? res.headers['content-disposition'].split('filename=')[1] : (t == 1 ? 'down.csv' : 'down.txt');
        t == 1 ? createExcel(res.data, name) : creatTxt(res.data, name);
    })
}
//disease带统计下载
const toDownDisease = (t) => {
    downDisease({...para.value,  exportType: t}).then(res => {
        const name = res.headers['content-disposition'] ? res.headers['content-disposition'].split('filename=')[1] : (t == 1 ? 'down.csv' : 'down.txt');
        t == 1 ? createExcel(res.data, name) : creatTxt(res.data, name);
    })
}
//disease-search下载
const toDownDiseaseSearch = (t) => {
    downDiseaseSearch({...para.value,  exportType: t}).then(res => {
        const name = res.headers['content-disposition'] ? res.headers['content-disposition'].split('filename=')[1] : (t == 1 ? 'down.csv' : 'down.txt');
        t == 1 ? createExcel(res.data, name) : creatTxt(res.data, name);
    })
}

//
const toDownPrescrIngre = (t) => {
    downPrescrIngre({...para.value,  exportType: t}).then(res => {
        const name = res.headers['content-disposition'] ? res.headers['content-disposition'].split('filename=')[1] : (t == 1 ? 'down.csv' : 'down.txt');
        t == 1 ? createExcel(res.data, name) : creatTxt(res.data, name);
    })
}

const toDownPrescrTarget = (t) => {
    downPrescrTarget({...para.value,  exportType: t}).then(res => {
        const name = res.headers['content-disposition'] ? res.headers['content-disposition'].split('filename=')[1] : (t == 1 ? 'down.csv' : 'down.txt');
        t == 1 ? createExcel(res.data, name) : creatTxt(res.data, name);
    })
}

const toDownPrescrExperimet = (t) => {
    downPrescrExperimet({...para.value,  exportType: t}).then(res => {
        const name = res.headers['content-disposition'] ? res.headers['content-disposition'].split('filename=')[1] : (t == 1 ? 'down.csv' : 'down.txt');
        t == 1 ? createExcel(res.data, name) : creatTxt(res.data, name);
    })
}

//herb详情下载
const toDownHerbDetail = (t) => {
    downHerbDetail({...para.value,  exportType: t}).then(res => {
        const name = res.headers['content-disposition'] ? res.headers['content-disposition'].split('filename=')[1] : (t == 1 ? 'down.csv' : 'down.txt');
        t == 1 ? createExcel(res.data, name) : creatTxt(res.data, name);
    })
}

//herb成分下载
const toDownHerbIngredient = (t) => {
    downHerbIngredient({...para.value,  exportType: t}).then(res => {
        const name = res.headers['content-disposition'] ? res.headers['content-disposition'].split('filename=')[1] : (t == 1 ? 'down.csv' : 'down.txt');
        t == 1 ? createExcel(res.data, name) : creatTxt(res.data, name);
    })
}
//
const toDownHerbTarget = (t) => {
    downHerbTarget({...para.value,  exportType: t}).then(res => {
        const name = res.headers['content-disposition'] ? res.headers['content-disposition'].split('filename=')[1] : (t == 1 ? 'down.csv' : 'down.txt');
        t == 1 ? createExcel(res.data, name) : creatTxt(res.data, name);
    })
}

//herb-实验数据下载
const toDownHerExperment = (t) => {
    downHerExperment({...para.value,  exportType: t}).then(res => {
        const name = res.headers['content-disposition'] ? res.headers['content-disposition'].split('filename=')[1] : (t == 1 ? 'down.csv' : 'down.txt');
        t == 1 ? createExcel(res.data, name) : creatTxt(res.data, name);
    })
}

//herb-network下载
const toDownHerbnetwork = (t) => {
    downHerbnetwork({...para.value,  exportType: t}).then(res => {
        const name = res.headers['content-disposition'] ? res.headers['content-disposition'].split('filename=')[1] : (t == 1 ? 'down.csv' : 'down.txt');
        t == 1 ? createExcel(res.data, name) : creatTxt(res.data, name);
    })
}

const toDownHerbPrescription = (t) => {
    downHerbPrescription({...para.value,  exportType: t}).then(res => {
        const name = res.headers['content-disposition'] ? res.headers['content-disposition'].split('filename=')[1] : (t == 1 ? 'down.csv' : 'down.txt');
        t == 1 ? createExcel(res.data, name) : creatTxt(res.data, name);
    })
}
const toDownHerbCombin = (t) => {
    downHerbCombin({...para.value,  exportType: t}).then(res => {
        const name = res.headers['content-disposition'] ? res.headers['content-disposition'].split('filename=')[1] : (t == 1 ? 'down.csv' : 'down.txt');
        t == 1 ? createExcel(res.data, name) : creatTxt(res.data, name);
    })
}

const toDownHerbDisease = (t) => {
    downHerbDisease({...para.value,  exportType: t}).then(res => {
        const name = res.headers['content-disposition'] ? res.headers['content-disposition'].split('filename=')[1] : (t == 1 ? 'down.csv' : 'down.txt');
        t == 1 ? createExcel(res.data, name) : creatTxt(res.data, name);
    })
}

/****
 *
 *
 * ingredient
 *
 */
const  toDownIngredientBasic = (t) => {
    downIngredientBasic({...para.value,  exportType: t}).then(res => {
        const name = res.headers['content-disposition'] ? res.headers['content-disposition'].split('filename=')[1] : (t == 1 ? 'down.csv' : 'down.txt');
        t == 1 ? createExcel(res.data, name) : creatTxt(res.data, name);
    })
}

const toDownIngreComTarget = (t) => {
    downIngreComTarget({...para.value,  exportType: t}).then(res => {
        const name = res.headers['content-disposition'] ? res.headers['content-disposition'].split('filename=')[1] : (t == 1 ? 'down.csv' : 'down.txt');
        t == 1 ? createExcel(res.data, name) : creatTxt(res.data, name);
    })
}

const toDownIngredientRelateHerb = (t) => {
    downIngreRelateHerb({...para.value,  exportType: t}).then(res => {
        const name = res.headers['content-disposition'] ? res.headers['content-disposition'].split('filename=')[1] : (t == 1 ? 'down.csv' : 'down.txt');
        t == 1 ? createExcel(res.data, name) : creatTxt(res.data, name);
    })
}

const toDownIngreRelateIngre = (t) => {
    downIngreRelateIngre({...para.value,  exportType: t}).then(res => {
        const name = res.headers['content-disposition'] ? res.headers['content-disposition'].split('filename=')[1] : (t == 1 ? 'down.csv' : 'down.txt');
        t == 1 ? createExcel(res.data, name) : creatTxt(res.data, name);
    })
}

const toDownAsyerIngre = (t) => (
    downSynerIngre({...para.value,  exportType: t}).then(res => {
        const name = res.headers['content-disposition'] ? res.headers['content-disposition'].split('filename=')[1] : (t == 1 ? 'down.csv' : 'down.txt');
        t == 1 ? createExcel(res.data, name) : creatTxt(res.data, name);
    })
)
const toDownAsyerDisease = (t) => {
    downSynerDisease({...para.value,  exportType: t}).then(res => {
        const name = res.headers['content-disposition'] ? res.headers['content-disposition'].split('filename=')[1] : (t == 1 ? 'down.csv' : 'down.txt');
        t == 1 ? createExcel(res.data, name) : creatTxt(res.data, name);
    })
}
//ingredient-实验数据下载
const toDownExperIngreRecords = (t) => {
    downExperIngreRecords({...para.value,  exportType: t}).then(res => {
        const name = res.headers['content-disposition'] ? res.headers['content-disposition'].split('filename=')[1] : (t == 1 ? 'down.csv' : 'down.txt');
        t == 1 ? createExcel(res.data, name) : creatTxt(res.data, name);
    })
}

/***
 * disease详情
 *
 */
//basic基本信息
const toDownDiseaseBasic = (t) => {
    downDiseaseBasic({...para.value,  exportType: t}).then(res => {
        const name = res.headers['content-disposition'] ? res.headers['content-disposition'].split('filename=')[1] : (t == 1 ? 'down.csv' : 'down.txt');
        t == 1 ? createExcel(res.data, name) : creatTxt(res.data, name);
    })
}

//disease与ingredient的关系下载
const toDownDiseaseAssIngre = (t) => {
    downDiseaseAssIngre({...para.value,  exportType: t}).then(res => {
        const name = res.headers['content-disposition'] ? res.headers['content-disposition'].split('filename=')[1] : (t == 1 ? 'down.csv' : 'down.txt');
        t == 1 ? createExcel(res.data, name) : creatTxt(res.data, name);
    })
}

//disease与herb关系下载
const toDiseaseAssHerb = (t) => {
    downDiseaseAssHerb({...para.value,  exportType: t}).then(res => {
        const name = res.headers['content-disposition'] ? res.headers['content-disposition'].split('filename=')[1] : (t == 1 ? 'down.csv' : 'down.txt');
        t == 1 ? createExcel(res.data, name) : creatTxt(res.data, name);
    })
}

//disease与prescription关系下载
const toDowmDiseaseAssPres = (t) => {
    dowmDiseaseAssPres({...para.value,  exportType: t}).then(res => {
        const name = res.headers['content-disposition'] ? res.headers['content-disposition'].split('filename=')[1] : (t == 1 ? 'down.csv' : 'down.txt');
        t == 1 ? createExcel(res.data, name) : creatTxt(res.data, name);
    })
}

//组合
const toDownHerbherbNetwork = (t) => {
    downHerbherbNetwork({...para.value,  exportType: t}).then(res => {
        const name = res.headers['content-disposition'] ? res.headers['content-disposition'].split('filename=')[1] : (t == 1 ? 'down.csv' : 'down.txt');
        t == 1 ? createExcel(res.data, name) : creatTxt(res.data, name);
    })
}
const toDowningreingreNetwork = (t) => {
    downingreingreNetwork({...para.value,  exportType: t}).then(res => {
        const name = res.headers['content-disposition'] ? res.headers['content-disposition'].split('filename=')[1] : (t == 1 ? 'down.csv' : 'down.txt');
        t == 1 ? createExcel(res.data, name) : creatTxt(res.data, name);
    })
}

const toDownPreDiseaNetwork = (t) => {
    downPreDiseaNetwork({...para.value,  exportType: t}).then(res => {
        const name = res.headers['content-disposition'] ? res.headers['content-disposition'].split('filename=')[1] : (t == 1 ? 'down.csv' : 'down.txt');
        t == 1 ? createExcel(res.data, name) : creatTxt(res.data, name);
    })
}

const toDownHerbDiseaNetwork = (t) => {
    downHerbDiseaNetwork({...para.value,  exportType: t}).then(res => {
        const name = res.headers['content-disposition'] ? res.headers['content-disposition'].split('filename=')[1] : (t == 1 ? 'down.csv' : 'down.txt');
        t == 1 ? createExcel(res.data, name) : creatTxt(res.data, name);
    })
}

const toDownIngreDiseaNetwork = (t) => {
    downIngreDiseaNetwork({...para.value,  exportType: t}).then(res => {
        const name = res.headers['content-disposition'] ? res.headers['content-disposition'].split('filename=')[1] : (t == 1 ? 'down.csv' : 'down.txt');
        t == 1 ? createExcel(res.data, name) : creatTxt(res.data, name);
    })
}

const toDownAdmetpage = (t) => {
    downAdmetpage({...para.value,  exportType: t}).then(res => {
        const name = res.headers['content-disposition'] ? res.headers['content-disposition'].split('filename=')[1] : (t == 1 ? 'down.csv' : 'down.txt');
        t == 1 ? createExcel(res.data, name) : creatTxt(res.data, name);
    })
}
</script>


<style lang="scss" scoped>
    .search-load-comp {
        display: inline-block;
        .load-cont {
            min-width: 44px;
            height: 32px;
            padding: 0 6px 0 8px;
            line-height: 32px;
            text-align: center;
            border: 1px solid #BC9F77;
            border-radius: 4px;
            color: #BC9F77;
            user-select: none;
            cursor: pointer;
            &:hover {
                color: #E6C896;
                .hover-img {
                    display: inline-block;
                }
                .show-img, .active-img {
                    display: none;
                }
            }
            &:active {
                color: #967846;
                .active-img {
                    display: inline-block;
                }
                .hover-img, .show-img {
                    display: none;
                }
            }
            .hover-img, .active-img {
                display: none;
            }
            .img-wrap {
                position: relative;
                display: inline-block;
                top: 2px;
                .load-img {
                    height: 16px;
                }
            }
            .arrow-box {
                padding-left: 6px;
            }
        }
    }
</style>




<style lang="scss">
    .load-drop-box {
        width: auto !important;
        padding: 0 !important;
        .load-cont-box {
            // color: red;
            font-weight: 400;
            font-size: 14px;
            .load-cont-wrap {
                .load-item {
                    height: 40px;
                    line-height: 40px;
                    text-align: center;
                    border-bottom: 1px solid #ddd;
                    cursor: pointer;
                    &:last-child {
                        border-bottom: none;
                    }
                }
            }
        }
    }
</style>
